package com.LeeCode;

/**
 * 使用最小花费爬楼梯
 */

public class Code746 {
    public static void main(String[] args) {
        int[] nums = {10, 15, 20};
        System.out.println(new Code746().minCostClimbingStairs(nums));
    }

    public int minCostClimbingStairs(int[] cost) {
        int n = cost.length;
        int cost1 = 0, cost2 = 0;
        int ans = cost1;
        for (int i = 2; i <= n; i++) {
            ans = Math.min(cost1 + cost[i - 2], cost2 + cost[i - 1]);
            cost1 = cost2;
            cost2 = ans;
        }
        return ans;
    }
}
